package cn.edy.cqut;

interface DogState {
    public void showState();
}
class SoftlyState implements DogState {
    public void showState() {
        System.out.println("听主⼈的命令");
    }
}
class MeetEnemyState implements DogState {

    @Override
    public void showState() {
        System.out.println("狂叫，冲过去咬人");
    }
}
class MeetFriendState implements DogState {
    public void showState() {
        System.out.println("晃动尾巴，表示欢迎 ");
    }
}
class MeetAnotherDog implements DogState {
    public void showState() {
        System.out.println("嬉戏");
    }
}
class Dog {
    DogState state;
    public void show() {
        state.showState();
    }
    public void setState(DogState s) {
        state = s;
    }
}
public class CheckDogState {
    public static void main(String args[]) {
        Dog yellowDog = new Dog();
        System.out.print("狗在主⼈⾯前:");
        yellowDog.setState(new SoftlyState());
        yellowDog.show();
        System.out.print("狗遇到敌⼈:");
        yellowDog.setState(new MeetEnemyState());
        yellowDog.show();
        System.out.print("狗遇到朋友:");
        yellowDog.setState(new MeetFriendState());
        yellowDog.show();
        System.out.print("狗遇到同伴:");
        yellowDog.setState(new MeetAnotherDog());
        yellowDog.show();
    }
}